﻿using DevExpress.XtraGrid.Demos.util;
using DiaoPaiDaYin;
using DXApplicationTangche.service;
using DXApplicationTangche.Utils;
using mendian;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.标签打印
{
    public partial class Form发货贴 : DevExpress.XtraEditors.XtraForm
    {
        private SfExpressMessageResult sfExpressMessageResult;
        private orderReqContactInfo orderReqContactInfo;
        public Form发货贴()
        {
            InitializeComponent();
        }

        private void textBox生产批号_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                try
                {
                    String json;
                    if (this.checkBox是否两联.Checked)
                    {
                        json = RestCall.PostHttp("http://192.168.3.33:8090/sf/sfExpressOrderByBatchNo?size=2", this.textBox生产批号.Text.Trim());
                    }
                    else
                    {
                        json = RestCall.PostHttp("http://192.168.3.33:8090/sf/sfExpressOrderByBatchNo?size=3", this.textBox生产批号.Text.Trim());
                    }
                    this.sfExpressMessageResult = FunctionHelper.JsonDeserialization<SfExpressMessageResult>(json);
                    if (sfExpressMessageResult.errorCode.Contains("200"))
                    {
                        //this.orderReqContactInfo = FunctionHelper.JsonDeserialization<orderReqContactInfo>(sfExpressMessageResult.orderReqContactInfo);
                        FileUtil.DownloadPicture("http://192.168.3.33:4545/sfexpress/" + this.textBox生产批号.Text.Trim() + ".jpg", @"pic\" + this.textBox生产批号.Text.Trim() + ".jpg", -1);
                        System.Diagnostics.Process.Start(@"pic\" + this.textBox生产批号.Text.Trim() + ".jpg");
                        //this.顺丰日志();
                    }
                    else
                    {
                        MessageBox.Show(sfExpressMessageResult.errorMessage);
                        this.textBox生产批号.Clear();
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        
    }

    public class SfExpressMessageResult
    {
        public String errorCode { get; set; }
        public String errorMessage { get; set; }
        public String sfExpressNo { get; set; }
        public String orderReqContactInfo { get; set; }
        public SfExpressMessageResult()
        {

        }
    }
    public class orderReqContactInfo
    {
        public String address { get; set; }//详细地址
        public String city { get; set; }//城市
        public String company { get; set; }//公司
        public String contact { get; set; }//联系人
        public int contactType { get; set; }//类型1是寄件2是收件
        public String country { get; set; }//县
        public String mobile { get; set; }//手机
        public String province { get; set; }//省
        public String postCode { get; set; }//邮编
        public String tel { get; set; }

        public orderReqContactInfo()
        {

        }

        public String getAddress()
        {
            return this.province + this.city + this.country + this.address;
        }
    }
}
